﻿Imports System.IO

Public Class Form1
    Public vernyyotvet As Integer
    Dim ttexts As String
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox2.Text = TextBox2.Text + 1
        If TextBox3.Text < TextBox2.Text Then
            TextBox2.Text = TextBox3.Text
            MsgBox("Данное значение не может быть больше значения максимального числа вопросов")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox2.Text = TextBox2.Text - 1
        If TextBox2.Text < 1 Then
            TextBox2.Text = 1
            MsgBox("Данное значение не может быть ниже 1")
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox3.Text = TextBox3.Text + 1
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox3.Text = TextBox3.Text - 1
        If TextBox3.Text < 1 Then
            TextBox3.Text = 1
            MsgBox("Данное значение не может быть ниже 1")
        End If
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Form2.Visible = True
        Form2.Label1.Text = TextBox4.Text
        Form2.RadioButton1.Text = TextBox5.Text
        Form2.RadioButton2.Text = TextBox6.Text
        Form2.RadioButton3.Text = TextBox7.Text
        Form2.RadioButton4.Text = TextBox8.Text
    End Sub

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        vernyyotvet = 1
    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        vernyyotvet = 2
    End Sub

    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
        vernyyotvet = 3
    End Sub

    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
        vernyyotvet = 4
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        'Генерирование вопроса
        Dim vopros As String
        vopros = TextBox4.Text & vbCrLf & TextBox5.Text & vbCrLf & TextBox6.Text & vbCrLf & TextBox7.Text & vbCrLf & TextBox8.Text & vbCrLf & vernyyotvet

        'Создание дериктории
        Dim di As DirectoryInfo = New DirectoryInfo(My.Application.Info.DirectoryPath & "\data\testbox\" & TextBox1.Text)
        di.Create()
        'Сохранение вопроса
        Dim Savefile As Integer
        Savefile = FreeFile()
        FileOpen(Savefile, My.Application.Info.DirectoryPath & "\data\testbox\" & TextBox1.Text & "\" & TextBox2.Text, OpenMode.Output)
        PrintLine(Savefile, vopros)
        FileClose(Savefile)
        'Сохранение setting
        Dim Savefile2 As Integer
        Savefile2 = FreeFile()
        FileOpen(Savefile2, My.Application.Info.DirectoryPath & "\data\testbox\" & TextBox1.Text & "\setting.conf", OpenMode.Output)
        PrintLine(Savefile2, TextBox3.Text)
        FileClose(Savefile2)
        'Нумерации
        TextBox4.Text = TextBox4.Text.Replace(vbCrLf, " ")
        If CheckBox1.Checked = True Then
            TextBox2.Text = TextBox2.Text + 1
            TextBox2.Text = TextBox3.Text
            MsgBox("Тест создан")
        End If
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Me.Close()
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        'open
        Dim R As New IO.StreamReader(My.Application.Info.DirectoryPath & "\data\testname")
        ttexts = R.ReadToEnd
        R.Close()
        MsgBox(ttexts)
        'replace
        ttexts = ttexts & vbCrLf & TextBox1.Text
        'save
        Dim savef As New System.IO.StreamWriter(My.Application.Info.DirectoryPath & "\data\testname")
        savef.Write(ttexts)
        savef.Close()
    End Sub
End Class
